package com.shigen.file.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger2的配置类
 *
 * @author shigenfu
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

  @Bean
  public Docket createRestApi(Environment environment) {
    // 判断是否是实际的生产环境 enable是否启动swagger
    Profiles profiles = Profiles.of("dev", "test");
    boolean flag = environment.acceptsProfiles(profiles);

    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .enable(flag)
        .groupName("shigen");
  }

  private ApiInfo apiInfo() {
    return new ApiInfoBuilder().title("XXX System Swagger2 Api Documentation")
        .description("shigen 自由表单数据收集+文件在线预览系统")
        .version("v1.2.0")
        .termsOfServiceUrl("http://81.68.145.94")
        .build();
  }
}
